public class CxG_CampaignMemberControlGroup{

    List <CXG_Campaign_Accounts__c> masterFetchedCampMemList = new List <CXG_Campaign_Accounts__c>();

 public void AssignControlGroupMember(List<Campaign> campList){        
        Decimal limitvalue;
        ID CxGcampaignmemberrecordtypeID = RecordTypeHelper.GetRecordTypeIdByDevName('CXG_Campaign_Accounts__c', 'Campaign_Member');       
        List<CXG_Campaign_Accounts__c> CampMemberFetchedList= new List<CXG_Campaign_Accounts__c>();       
        List<CXG_Campaign_Accounts__c> CampMemberUpdateList = new List<CXG_Campaign_Accounts__c>();
        Set<ID> CampaignIdSet = New Set<ID>();

        for(Campaign camprecord : campList){
            limitvalue = camprecord.Number_of_Control_Group_Members__c;
            //system.debug('The NNNNN a'+limitvalue);  
            //CampaignIdSet.add(camprecord.id);
            String campMemberQueryString=null;       
            campMemberQueryString = 'Select id, Campaign__c,Campaign__r.Number_of_Control_Group_Members__c,Campaign__r.StartDate from CXG_Campaign_Accounts__c where recordtypeid =: CxGcampaignmemberrecordtypeID and Status__c =\'' + 'New' + '\' and Control_Group_Member__c = False and Campaign__C =\'' + camprecord.Id + '\' limit '+ limitvalue;
            //system.debug('TTTTTT'+campMemberQueryString);
            CampMemberFetchedList = Database.Query(campMemberQueryString);
            // CampaignIdSet.remove(camprecord.id);                                        
            if(CampMemberFetchedList.size()>0){
                //system.debug('Number'+CampMemberFetchedList);
                masterFetchedCampaignMember(CampMemberFetchedList);
                //system.debug('CCC' +masterFetchedCampMemList);
                CampMemberFetchedList.clear();
  
            }
        }
            update  masterFetchedCampMemList; 
            //system.debug('The NNNNN b'+limitvalue);        
            //system.debug('Campaign IDD '+CampaignIdSet);                   
            //system.debug('DDDDDDD'+masterFetchedCampMemList);
            //system.debug('SSSSS' +masterFetchedCampMemList.size());    
                
   /** for(CXG_Campaign_Accounts__c cm: masterFetchedCampMemList){
            {
            cm.Control_Group_Member__c = True;
            cm.Start_Date__c = cm.Campaign__r.StartDate;
            cm.ownerid='005Q0000000dN0r';
            }
            CampMemberUpdateList.add(cm);
            system.debug('DDDDD '+cm);
            }
        update CampMemberUpdateList;
        system.debug('OOOOOOOOOOOO '+CampMemberUpdateList);*/
}   
 QueueSobject CTRid=[Select QueueId from QueueSobject where Queue.Name ='Control Group Queue' Limit 1]; 
   public  void masterFetchedCampaignMember(list<CXG_Campaign_Accounts__c> CampMemberFetchedList){
   
   for(CXG_Campaign_Accounts__c c : CampMemberFetchedList){
         
       system.debug('LOLOLOL ' +c.id); 
       c.Control_Group_Member__c = True;
       c.Start_Date__c = System.today();
       //c.ownerid='00GQ00000010fYv';
       c.OwnerId=CTRid.QueueId;
       masterFetchedCampMemList.add(c);    
       
    //system.debug('EXIT METHODDDDD '+masterFetchedCampMemList);  
  }
}

public  void RemoveControlGroupMember(List<CXG_Campaign_Accounts__c> campmemlist){

List<CXG_Campaign_Accounts__c> campaignMember = new List<CXG_Campaign_Accounts__c>();
QueueSobject Qid = [Select QueueId from QueueSobject where Queue.Name ='Agent Queue' LIMIT 1];
    for(CXG_Campaign_Accounts__c camMem: campmemlist){
        camMem.Ownerid=Qid.Queueid;
        camMem.Control_Group_Member__c=False;
        campaignMember.add(camMem);
    }
update campaignMember;   
    
}

}